package org.song.util.email;

import org.song.constant.EmailConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * springboot 邮件任务的 工具类
 */
@Component( value = "emailUtil")
public class EmailUtil {
    //自动注入 spring框架中的 邮件发送依赖

    @Autowired
    private  JavaMailSenderImpl mailSender;

    //使用异步任务完成 普通的邮件任务
    @Async
    public  void sendEasyEmail(String title, String text) {
        SimpleMailMessage message = new SimpleMailMessage();

        message.setSubject(title);	//标题
        message.setText(text);	//正文

        message.setTo( EmailConstant.RECIPIENT_EMAIL );	//接收者
        message.setFrom( EmailConstant.SENDER_EMAIL );	//发送者

        //发送邮件 需要SimpleMailMessage 对象用来存储具体内容的。
        mailSender.send(message);
    }


}
